package com.gxuwz.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import com.gxuwz.model.Catalog;
import com.gxuwz.util.DBUtil;

/**
 * 高校目录DAO
 * 
 * @author h
 * 
 */
public class CatalogDao {

	private static Connection conn = null;
	private static Statement stmt = null;

	public static void save(List<Catalog> catalogs){
		try{
		conn = DBUtil.getConnection();
		conn.setAutoCommit(false);
		stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
				ResultSet.CONCUR_READ_ONLY);
		for (Catalog catalog : catalogs) {
			System.out.println("高校名字："+catalog.getCatalogName()+"----链接:"+catalog.getCatalogURL());
			stmt.execute("insert into catalog(catalogName,catalogURL,catalogProvince) values('"+catalog.getCatalogName()+"','"+catalog.getCatalogURL()+"','"+catalog.getCatalogProvince()+"')");
		}
		conn.commit();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try{
			stmt.close();
			conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}

	public static ResultSet queryByName(String catalogName) throws SQLException {
		conn = DBUtil.getConnection();
		stmt = conn.createStatement();
		ResultSet rs = stmt
				.executeQuery("select * from catalog where catalogName = '"
						+ catalogName + "'");
		return rs;
	}

}
